﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BUS;
namespace baitaptuan5
{
    public partial class BCTKSach : Form
    {
        public BCTKSach()
        {
            InitializeComponent();
        }

        private void BCTKSach_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'DataSetSach.Sach' table. You can move, or remove it, as needed.
            SachBUS sach = new SachBUS();
            DataTable dt = new DataTable();
            dt = sach.laybang();
            this.SachTableAdapter.Fill(this.DataSetSach.Sach);

            this.reportViewer1.RefreshReport();

            AutoCompleteStringCollection auto = new  AutoCompleteStringCollection();
            txtBaoCaoTenSach.AutoCompleteMode = AutoCompleteMode.Suggest;
            txtBaoCaoTenSach.AutoCompleteSource = AutoCompleteSource.CustomSource;

            SachBUS sbus = new SachBUS();
            DataTable dtThongKeSach = sbus.laybang();

            foreach( DataRow r  in dtThongKeSach.Rows)
            {
                auto.Add(r["TenSach"].ToString());
                

            }
            //combobox
            TacGiaBUS tgbus = new TacGiaBUS();

            DataTable dsTacGia = tgbus.laybang();
            cbbTacGia.DataSource = dtThongKeSach;
            cbbTacGia.DisplayMember = "TenTacGia";
            cbbTacGia.ValueMember = "MaTG";



            txtBaoCaoTenSach.AutoCompleteCustomSource=auto;


        }

        private void groupBox1_Enter(object sender, EventArgs e)
        {

        }

        private void btnThongKe_Click(object sender, EventArgs e)
        {
            if (chkBaoCaoTen.Checked)
            {
                if (txtBaoCaoTenSach.Text.Trim() == "")
                    MessageBox.Show("Chưa Nhâp Tên Sách");
                else
                {
                    this.SachTableAdapter.FillBy(this.DataSetSach.Sach, txtBaoCaoTenSach.Text);

                    this.reportViewer1.RefreshReport();
                }
            }
            if (chkBaoCaoTacGia.Checked)

            {
                //int t = int.Parse(cbbTacGia.SelectedValue.ToString());
                this.SachTableAdapter.FillBy2(this.DataSetSach.Sach,int.Parse(cbbTacGia.SelectedValue.ToString()));
                this.reportViewer1.RefreshReport();
            }
            

            
        }

        private void chkBaoCaoTen_CheckedChanged(object sender, EventArgs e)
        {
            txtBaoCaoTenSach.Enabled = chkBaoCaoTen.Checked;
        }

        private void tảiLạiToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.SachTableAdapter.Fill(this.DataSetSach.Sach);

            this.reportViewer1.RefreshReport();
        }

        private void thoatToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void chkBaoCaoTacGia_CheckedChanged(object sender, EventArgs e)
        {
            cbbTacGia.Enabled = chkBaoCaoTacGia.Checked;
        }
    }
}
